{% extends 'base.html' %}
{% load buttons %}
{% load custom_links %}
{% load helpers %}
{% load perms %}
{% load plugins %}
{% load static %}
{% load tz %}

{% block header %}
    <div class="row noprint">
        {% with list_url=object|validated_viewname:"list" %}
        <div class="col-sm-8 col-md-9">
            <ol class="breadcrumb">
            {% block breadcrumbs %}
                <li><a href="{% url list_url %}">
                    {{ verbose_name_plural|bettertitle }}
                </a></li>
                {% block extra_breadcrumbs %}{% endblock extra_breadcrumbs %}
                {% if object.name %}
                    <li><a href="{{ object.get_absolute_url }}">{{ object.name }}</a></li>
                {% else %}
                    <li><a href="{{ object.get_absolute_url }}">{{ object }}</a></li>
                {% endif %}
            {% endblock breadcrumbs %}
            </ol>
        </div>
        <div class="col-sm-4 col-md-3">
            <form action="{% url list_url %}" method="get">
                <div class="input-group">
                    <input type="text" name="q" class="form-control" placeholder="Search {{ verbose_name_plural }}" />
                    <span class="input-group-btn">
                        <button type="submit" class="btn btn-primary">
                            <span class="mdi mdi-magnify" aria-hidden="true"></span>
                        </button>
                    </span>
                </div>
            </form>
        </div>
        {% endwith %}
    </div>

    <div class="pull-right noprint">
    {% block buttons %}
        {% plugin_buttons object %}
        {% block extra_buttons %}{% endblock extra_buttons %}
        {% if object.clone_fields and user|can_add:object %}
            {% clone_button object %}
        {% endif %}
        {% if user|can_change:object %}
            {% edit_button object %}
        {% endif %}
        {% if user|can_delete:object %}
            {% delete_button object %}
        {% endif %}
    {% endblock buttons %}
    </div>

    {% block masthead %}
        <h1>{% block title %}{{ object }}{% endblock %}</h1>
    {% endblock masthead %}
    {% include 'inc/created_updated.html' %}
    <div class="pull-right noprint">
        {% custom_links object %}
        {% block panel_buttons %}{% endblock panel_buttons %}
    </div>

    <ul class="nav nav-tabs">
    {% block nav_tabs %}
        <li role="presentation"{% if not active_tab and not request.GET.tab or request.GET.tab == "main" %} class="active"{% endif %}>
            <a href="{{ object.get_absolute_url }}#main" onclick="switch_tab(this.href)" aria-controls="main" role="tab" data-toggle="tab">
                {{ verbose_name|bettertitle }}
            </a>
        </li>
        <li role="presentation"{% if request.GET.tab == 'advanced' %} class="active"{% endif %}>
            <a href="{{ object.get_absolute_url }}#advanced" onclick="switch_tab(this.href)" aria-controls="advanced" role="tab" data-toggle="tab">
                Advanced
            </a>
        </li>
        {% block extra_nav_tabs %}{% endblock extra_nav_tabs %}
        {% if perms.extras.view_objectchange %}
            {% if active_tab != 'changelog' and changelog_url or active_tab == 'changelog' %}
            <li role="presentation"{% if active_tab == 'changelog' %} class="active"{% endif %}>
                <a href="{{ changelog_url }}">Change Log</a>
            </li>
            {% endif %}
        {% endif %}
    {% endblock nav_tabs %}
    </ul>
{% endblock header %}

{% block content %}
    <div class="tab-content">
        <div id="main" role="tabpanel" class="tab-pane {% if not active_tab and not request.GET.tab or request.GET.tab == "main" %}active{% else %}fade{% endif %}">
            <div class="row">
                <div class="col-md-6">
                    {% block content_left_page %}{% endblock content_left_page %}
                    {% include 'inc/custom_fields_panel.html' %}
                    {% include 'inc/relationships_panel.html' %}
                    {% include 'extras/inc/tags_panel.html' %}
                    {% plugin_left_page object %}
                </div>
                <div class="col-md-6">
                    {% block content_right_page %}{% endblock content_right_page %}
                    {% plugin_right_page object %}
                </div>
            </div>
            <div class="row">
                <div class="col-md-12">
                    {% block content_full_width_page %}{% endblock content_full_width_page %}
                    {% plugin_full_width_page object %}
                </div>
            </div>
        </div>
        <div id="advanced" role="tabpanel" class="tab-pane {% if request.GET.tab == 'advanced' %}active{% else %}fade{% endif %}">
            <div class="row">
                <div class="col-md-6">
                    {% include 'inc/object_details_advanced_panel.html' %}
                </div>
                <div class="col-md-6">
                    {% block advanced_content_right_page %}{% endblock advanced_content_right_page %}
                </div>
            </div>
            <div class="row">
                <div class="col-md-12">
                    {% block advanced_content_full_width_page %}{% endblock advanced_content_full_width_page %}
                </div>
            </div>
        </div>
    </div>
{% endblock content %}


{% block javascript %}
<script src="{% static 'clipboard.js/clipboard-2.0.6.min.js' %}"
    onerror="window.location='{% url 'media_failure' %}?filename=clipboard.js/clipboard-2.0.6.min.js'">
</script>
<script>
    url = window.location.href.split("?")[0];
    window.history.pushState({}, document.title, url);
    var clipboard = new ClipboardJS('.btn');

    clipboard.on('success', function (e) {});

    clipboard.on('error', function (e) {});

    function switch_tab(tab_href) {
        if (location.pathname != "{{ object.get_absolute_url }}") {
            tab_location = tab_href.split("#");
            window.location.href = `${tab_location[0]}?tab=${tab_location[1]}`;
        };
    }
</script>
{% endblock javascript %}
